package com.qianbao.dao.money;


import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface ReadTimeDao {


    /**
     * 更新用户的阅读时长
     * @param custom_id
     * @param readtime
     * @return
     */
    @Insert("INSERT INTO sys_user_readtime (read_time,custom_id) " +
            "VALUES (#{readtime},#{custom_id}) " +
            "ON DUPLICATE KEY UPDATE read_time = read_time + #{readtime}")
    public int saveUserReadTime(@Param("custom_id")String custom_id,
                                @Param("readtime")int readtime);


    /**
     * 查询用户的阅读时长
     * @param custom_id
     * @return
     */
    @Select("SELECT IFNULL(MAX(read_time),0) FROM sys_user_readtime WHERE custom_id = #{custom_id}")
    public int findUserReadTime(String custom_id);


    /**
     * 更新用户的阅读时长，这个更多用来清零
     * @param custom_id
     * @param readtime
     * @return
     */
    @Update("update sys_user_readtime set read_time = #{readtime} where custom_id = #{custom_id}")
    public int updateUserReadTime(@Param("custom_id")String custom_id,
                                  @Param("readtime")int readtime);



}
